package com.example.monitordemo.constant;

import static com.example.monitordemo.config.MonitorConfig.JVM_APPLICATION;
import static com.example.monitordemo.config.MonitorConfig.JVM_INSTANCE;

public interface JVMConstant {

    /**
     * SLA百分比
     */
    String SLA_PERCENT = "100-sum(rate(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", status!~\"5..\"}[1m]))/sum(rate(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m]))-0.01";
    /**
     * 进程启动时长
     */
    String PROCESS_UP_TIME = "process_uptime_seconds{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 堆内存使用率
     */
    String MEMORY_USE_RATE = "sum(jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"heap\"})*100/sum(jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\",instance=\""+JVM_INSTANCE+"\", area=\"heap\"})";
    /**
     * 非堆内存使用率
     */
    String NOT_MEMORY_USE_RATE = "sum(jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"nonheap\"})*100/sum(jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\",instance=\""+JVM_INSTANCE+"\", area=\"nonheap\"})";
    /**
     * QPS(1分钟平均)
     */
    String QPS_MINUTE = "sum(rate(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m]))";
    /**
     * 错误数(1分钟平均)
     */
    String ERROR_NUM_MINUTE = "sum(rate(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", status=~\"5..\"}[1m]))";
    /**
     * 请求耗时(1分钟平均) 最大
     */
    String REQUEST_TIME_MAX = "max(http_server_requests_seconds_max{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", status!~\"5..\"})";
    /**
     * 请求耗时(1分钟平均) 平均
     */
    String REQUEST_TIME_AVG = "sum(rate(http_server_requests_seconds_sum{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", status!~\"5..\"}[1m]))/sum(rate(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", status!~\"5..\"}[1m]))";
    /**
     * 饱和度-tomcat忙线程
     */
    String TOMCAT_BUSY_THREADS = "tomcat_threads_busy_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 饱和度-tomcat当前线程
     */
    String TOMCAT_CURRENT_THREADS = "tomcat_threads_current_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 饱和度-tomcat配置最大线程
     */
    String TOMCAT_CONFIG_MAX_THREADS = "tomcat_threads_config_max_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 饱和度-jetty忙线程
     */
    String JETTY_BUSY_THREADS = "jetty_threads_busy{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 饱和度-jetty当前线程
     */
    String JETTY_CURRENT_THREADS = "jetty_threads_current{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 饱和度-jetty配置最大线程
     */
    String JETTY_CONFIG_MAX_THREADS = "jetty_threads_config_max{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 平均响应时间-单位毫秒
     */
    String AVG_RESPONSE_TIME = "avg(http_server_requests_seconds_sum{instance=\""+JVM_INSTANCE+"\",application=\""+JVM_APPLICATION+"\"}/http_server_requests_seconds_count{instance=\""+JVM_INSTANCE+"\",application=\""+JVM_APPLICATION+"\"} * 1000)";
    /**
     * P95响应时间-废弃
     */
    String P95_RESPONSE_TIME = "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])) by (le))*1000";
    /**
     * 请求次数前十的接口
     */
    String COUNT_TOP10_REQUEST = "topk(10, sum by(uri)(http_server_requests_seconds_count{application=\""+JVM_APPLICATION+"\",uri!=\"/actuator/prometheus\"}))";

    /**
     * 请求响应时间最长的前十接口
     */
    String TIME_TOP10_REQUEST = "topk(10,sum by (uri)(http_server_requests_seconds_sum{instance=\""+JVM_INSTANCE+"\",application=\""+JVM_APPLICATION+"\"}/http_server_requests_seconds_count{instance=\""+JVM_INSTANCE+"\",application=\""+JVM_APPLICATION+"\", uri!=\"/actuator/prometheus\"}))*1000";

    /**
     * 系统CPU使用率
     */
    String SYSTEM_CPU_USE_RATE = "system_cpu_usage{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 进程CPU使用率
     */
    String PROCESS_CPU_USE_RATE = "process_cpu_usage{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 平均进程CPU使用率
     */
    String AVG_PROCESS_CPU_USE_RATE = "avg_over_time(process_cpu_usage{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1h])";
    /**
     * 负载
     */
    String LOAD = "system_cpu_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 活线程数
     */
    String LIVE_THREADS = "jvm_threads_live_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 守护线程数
     */
    String DAEMON_THREADS = "jvm_threads_daemon_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 自Java虚拟机启动或峰值重置以来的最高活动线程数。
     */
    String PEAK_THREADS = "jvm_threads_peak_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 各状态线程数
     */
    String STATES_THREADS = "jvm_threads_states_threads{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * Logback日志数
     */
    String LOGBACK_NUM = "increase(logback_events_total{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])";
    /**
     * 文件描述符-进程打开文件数
     */
    String PROCESS_OPEN_FILES = "process_files_open_files{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 文件描述符-进程最大文件数
     */
    String PROCESS_MAX_FILES = "process_files_max_files{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 堆内存-已用内存
     */
    String HEAP_USED_MEMORY = "sum(jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"heap\"})";
    /**
     * 堆内存-可用内存
     */
    String HEAP_USABLE_MEMORY = "sum(jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"heap\"})";
    /**
     * 堆内存-最大内存
     */
    String HEAP_MAX_MEMORY = "sum(jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"heap\"})";
    /**
     * 非堆内存-已用内存
     */
    String NOT_HEAP_USED_MEMORY = "sum(jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"nonheap\"})";
    /**
     * 非堆内存-可用内存
     */
    String NOT_HEAP_USABLE_MEMORY = "sum(jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"nonheap\"})";
    /**
     * 非堆内存-最大内存
     */
    String NOT_HEAP_MAX_MEMORY = "sum(jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", area=\"nonheap\"})";
    /**
     * 总内存-已用内存
     */
    String USED_MEMORY = "sum(jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"})";
    /**
     * 总内存-可用内存
     */
    String USABLE_MEMORY = "sum(jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"})";
    /**
     * 总内存-最大内存
     */
    String MAX_MEMORY = "sum(jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"})";
    /**
     * JVM进程内存-虚拟内存大小
     */
    String PROCESS_MEMORY_VSS_BYTES = "process_memory_vss_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * JVM进程内存-物理内存大小
     */
    String PROCESS_MEMORY_RSS_BYTES = "process_memory_rss_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * JVM进程内存-交换内存大小
     */
    String PROCESS_MEMORY_SWAP_BYTES = "process_memory_swap_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * JVM进程内存-物理内存加交换内存大小
     */
    String PROCESS_MEMORY_RSS_SWAP_BYTES = "process_memory_rss_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"} %2B process_memory_swap_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器年轻代内存区域 已用
     */
    String PS_EDEN_SPACE_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Eden Space\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器年轻代内存区域 可用
     */
    String PS_EDEN_SPACE_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Eden Space\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器年轻代内存区域 总共
     */
    String PS_EDEN_SPACE_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Eden Space\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器老年代内存区域 已用
     */
    String PS_OLD_GEN_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Old Gen\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器老年代内存区域 可用
     */
    String PS_OLD_GEN_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Old Gen\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器老年代内存区域 总共
     */
    String PS_OLD_GEN_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Old Gen\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器对称内存区域 已用
     * 在JVM中，PS Survivor Space指的是Parallel Scavenge收集器使用的两个小型对称的内存区域。这两个区域一般被称为survivor space或from space和to space。在对象进行Minor GC时，对象会被移动到这两个区域中的一个中，并将其年龄加1。当对象达到一定的年龄时，就会被移动到Old区域中。这种机制被称为分代收集。
     */
    String PS_SURVIVOR_SPACE_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Survivor Space\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器对称内存区域 可用
     */
    String PS_SURVIVOR_SPACE_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Survivor Space\"}";
    /**
     * JVM堆内存详细-并行垃圾回收器对称内存区域 总共
     */
    String PS_SURVIVOR_SPACE_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"PS Survivor Space\"}";
    /**
     * JVM非堆内存详细-元数据空间 已用
     */
    String METASPACE_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Metaspace\"}";
    /**
     * JVM非堆内存详细-元数据空间 可用
     */
    String METASPACE_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Metaspace\"}";
    /**
     * JVM非堆内存详细-元数据空间 总共
     */
    String METASPACE_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Metaspace\"}";

    /**
     * JVM非堆内存详细-已压缩类空间 已用
     */
    String COMPRESSED_CLASS_SPACE_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Compressed Class Space\"}";
    /**
     * JVM非堆内存详细-已压缩类空间 可用
     */
    String COMPRESSED_CLASS_SPACE_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Compressed Class Space\"}";
    /**
     * JVM非堆内存详细-已压缩类空间 总共
     */
    String COMPRESSED_CLASS_SPACE_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Compressed Class Space\"}";

    /**
     * JVM非堆内存详细-代码缓存 已用
     */
    String CODE_CACHE_USED = "jvm_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Code Cache\"}";
    /**
     * JVM非堆内存详细-代码缓存 可用
     */
    String CODE_CACHE_USABLE = "jvm_memory_committed_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Code Cache\"}";
    /**
     * JVM非堆内存详细-代码缓存 总共
     */
    String CODE_CACHE_MAX = "jvm_memory_max_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=~\"Code Cache\"}";

    /**
     * 垃圾回收（GC）- GC 次数
     */
    String GC_TIMES = "rate(jvm_gc_pause_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])";
    /**
     * 垃圾回收（GC）- 平均GC暂停时间
     */
    String AVG_GC_PAUSE_TIME = "sum by (cause,application) (rate(jvm_gc_pause_seconds_sum{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])/rate(jvm_gc_pause_seconds_count{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m]))";
    /**
     * 垃圾回收（GC）- 最大GC暂停时间
     */
    String MAX_GC_PAUSE_TIME = "sum(jvm_gc_pause_seconds_max{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}) by(cause,application)";
    /**
     * 垃圾回收（GC）-内存分配
     */
    String GC_MEMORY_ALLOCATED = "rate(jvm_gc_memory_allocated_bytes_total{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])";
    /**
     * 垃圾回收（GC）-内存晋升
     */
    String GC_MEMORY_PROMOTED = "rate(jvm_gc_memory_promoted_bytes_total{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}[1m])";
    /**
     * 已加载的类的数量
     */
    String LOADED_CLASSES_NUM = "jvm_classes_loaded_classes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\"}";
    /**
     * 加载类数量变化
     */
    String LOADED_CLASSES_NUM_DELTA = "delta(jvm_classes_loaded_classes{application=\""+JVM_APPLICATION+"\",instance=\""+JVM_INSTANCE+"\"}[1m])";
    /**
     * 缓冲区-直接缓冲区-已用
     */
    String DIRECT_BUFFERS_USABLE = "jvm_buffer_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"direct\"}";
    /**
     * 缓冲区-直接缓冲区-总共
     */
    String DIRECT_BUFFERS_MAX = "jvm_buffer_total_capacity_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"direct\"}";
    /**
     * 缓冲区-直接缓冲区-数量
     */
    String DIRECT_BUFFERS_NUM = "jvm_buffer_count_buffers{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"direct\"}";
    /**
     * 缓冲区-映射缓冲区-已用
     */
    String MAPPED_BUFFERS_USABLE = "jvm_buffer_memory_used_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"mapped\"}";
    /**
     * 缓冲区-映射缓冲区-总共
     */
    String MAPPED_BUFFERS_MAX = "jvm_buffer_total_capacity_bytes{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"mapped\"}";
    /**
     * 缓冲区-映射缓冲区-数量
     */
    String MAPPED_BUFFERS_NUM = "jvm_buffer_count_buffers{application=\""+JVM_APPLICATION+"\", instance=\""+JVM_INSTANCE+"\", id=\"mapped\"}";
    
}
